/*           Copyright(c) 2005-2008 Dave Sexton            *
 *                   HtmlEditor Control                    *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Security.Permissions;

namespace DaveSexton.Controls
{
	partial class HtmlEditor
	{
		private const int WM_KEYDOWN = 0x0100, WM_KEYUP = 0x0101;

		[PermissionSet(SecurityAction.LinkDemand, Unrestricted = true)]
		public override bool PreProcessMessage(ref Message msg)
		{
			switch (msg.Msg)
			{
				case WM_KEYDOWN:
					if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
					{
						switch ((Keys) msg.WParam)
						{
							case Keys.A:
								commands.SelectAll.Execute();
								return true;
							case Keys.X:
								commands.Cut.Execute();
								return true;
							case Keys.C:
								commands.Copy.Execute();
								return true;
							case Keys.V:
								commands.Paste.Execute();
								return true;
							case Keys.B:
								commands.Bold.Execute();
								return true;
							case Keys.I:
								commands.Italic.Execute();
								return true;
							case Keys.U:
								commands.Underline.Execute();
								return true;
							case Keys.Z:
								commands.Undo.Execute();
								return true;
							case Keys.Y:
								commands.Redo.Execute();
								return true;
						}
					}
					else
					{
						switch ((Keys) msg.WParam)
						{
							case Keys.Delete:
								commands.Delete.Execute();
								break;
						}
					}
					break;
			}

			return base.PreProcessMessage(ref msg);
		}
	}
}
